package greedy;

/**
 * @ Author     ：侯耀祖
 * @ Description：
 */
public class jump {
    public int jump(int[] nums) {
        int nextCover = 0;
        int curDistance = 0;
        int step = 0;
        if (nums.length == 1){
            return 0;
        }
        for (int i = 0; i <= nums.length; i++) {
            nextCover = Math.max(i + nums[i], nextCover);
            if (i == curDistance){
                step++;
                curDistance = nextCover;
                if (nextCover >= nums.length - 1) break;
            }
        }
        return step;
    }
}
